package com.bayes.teamshow.service;

import com.bayes.teamshow.dao.ArticleSearch;
import com.bayes.teamshow.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

@Service
public class ArticleSearchImp {
    @Autowired
    ArticleSearch articleSearch;
    //查询所有博客的标题、作者
    public List<Article> findAllArticals(){
        return articleSearch.findAll();

    }

    //查询共有多少篇博客文章
    public Integer BlogCounts(int perPageCount){
        int blogNum =  articleSearch.BlogCounts().intValue();
        return blogNum/perPageCount + 1;
    }


    //时间字符串换为Date类
    public Date timeStripToDate(String timeDate){
        SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        try {
            date= format.parse(timeDate);

        }catch (ParseException e){
            System.out.println(e);
        }
        return date;
    }


    //根据ID删除博客
    public void deleteBlog(int id){
        articleSearch.deleteById(id);
    }

}
